"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var types_1 = require("./types");
var parser_1 = require("./parser");
var lodash_1 = __importDefault(require("lodash"));
var union_1 = require("./union");
var intersection_1 = require("./intersection");
var diff_1 = require("./diff");
var print_1 = require("./print");
var not_1 = require("./not");
/**
 * 提供更友善的操作接口
 */
var hop = Object.prototype.hasOwnProperty;
function isExpressionIns(ins) {
    return hop.call(ins, 'exp');
}
var ExpressionIns = /** @class */ (function () {
    function ExpressionIns(exp) {
        this.exp = types_1.EMPTY;
        this.exp = this.anyToExpression(exp);
    }
    ExpressionIns.prototype.anyToExpression = function (exp) {
        if (typeof exp === 'string') {
            return parser_1.parse(exp);
        }
        else if (isExpressionIns(exp)) {
            return lodash_1.default.clone(exp.exp);
        }
        return exp;
    };
    // 交
    ExpressionIns.prototype.intersection = function (exp) {
        var expIns = this.anyToExpression(exp);
        var rstExp = intersection_1.intersection(this.exp, expIns);
        return new ExpressionIns(rstExp);
    };
    // 并
    ExpressionIns.prototype.union = function (exp) {
        var expIns = this.anyToExpression(exp);
        var rstExp = union_1.union(this.exp, expIns);
        return new ExpressionIns(rstExp);
    };
    // 差
    ExpressionIns.prototype.diff = function (exp) {
        var expIns = this.anyToExpression(exp);
        var rstExp = diff_1.diff(this.exp, expIns);
        return new ExpressionIns(rstExp);
    };
    // 取反
    ExpressionIns.prototype.not = function () {
        var rstExp = not_1.reverse(this.exp);
        return new ExpressionIns(rstExp);
    };
    ExpressionIns.prototype.toString = function () {
        return print_1.print(this.exp);
    };
    return ExpressionIns;
}());
exports.ExpressionIns = ExpressionIns;
